class code1 {
    //最大子数组和->dp
    public int maxSubArray(int[] nums) {
        int n = nums.length;
        int[] dp = new int[n];//以i下标结尾子数组的最大和
        dp[0] = nums[0];//就算是负数也得选
        int ret = Integer.MIN_VALUE;
        for (int i = 1; i < n; i++) {
            dp[i] = Math.max(nums[i],dp[i-1]+nums[i]);//dp[i-1]大于0和小于0
            ret = Math.max(ret,dp[i]);
        }
        return ret;
    }
}